package gov.child.dao;

import gov.child.dao.exception.PageInitialException;
import gov.child.entities.vo.Page;
import org.hibernate.query.Query;

import java.util.List;

/**
 * @author fzh
 * @since 2017/9/10
 */
public interface Pageable {
    default List doPaginate(Query query, Page page) {
        if (page.isSingle()) {
            return query.list();
        } else {
            return query.setFirstResult((page.getCurrentPage() - 1) * page.getEveryPage())
                    .setMaxResults(page.getEveryPage()).list();
        }
    }

    Long total() throws PageInitialException;
}
